package com.sadhoc.router.pdu;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import com.sadhoc.router.neighbor.NeighborTableEntry;

public class HelloMsg implements Serializable {
	
	private static final long serialVersionUID = 7488286447991890787L;
	
	// A hello message contains a list of all neighbors
	private HashMap<String, NeighborTableEntry> nodes;
	
	/*
	 * Constructor
	 */
	public HelloMsg(HashMap<String, NeighborTableEntry> nodes) {
		this.nodes = new HashMap<String, NeighborTableEntry>(nodes);
	}
	
	/*
	 * This method returns all nodes that are within the hello message 
	 */
	public HashMap<String, NeighborTableEntry> getNodes() {
		return nodes;
	}	
	
	/*
	 * Formats the hello message as a string
	 */
	public String toString() {
		
		String r = "";
		Set<String> set = nodes.keySet(); 
	    Iterator<String> itr = set.iterator(); 
	    while (itr.hasNext()) 
	    { 
        	Object key = itr.next();
        	r+= key.toString() + ":" + nodes.get(key).toString() + "\n";
	    }
	    return r;
	    
	}
}
